﻿//
// PhantomPhysicsComponent.cs
//
// This file is part of the QuickStart Engine. See http://www.codeplex.com/QuickStartEngine
// for license details.
//

using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Alex_s_Dream_The_Toy_World
{
    public class PhantomPhysicsComponent : PhysicsComponent
    {
        public PhantomPhysicsComponent(BaseEntity parent, ShapeType type, float density)
            : base(parent, type, density, false)
        {
        }

        /// <summary>
        /// Creates an actor using shape info and information from the parent BaseEntity.
        /// </summary>
        /// <param name="PhysicsScene">Reference to the physics scene</param>
        protected override void CreateActor(IPhysicsScene PhysicsScene)
        {
            ShapeDesc newShape = CreateShapeFromType(shapeType);

            // Phantoms cannot currently have dynamic physics
            this.isDynamic = false;

            ActorDesc desc = new ActorDesc();
            desc.Orientation = parentEntity.Rotation;
            desc.Density = this.density;
            desc.Dynamic = this.isDynamic;
            desc.Position = parentEntity.Position;
            desc.Shapes.Add(newShape);
            desc.EntityID = this.parentEntity.UniqueID;
            desc.Game = this.parentEntity.Game;
            desc.Phantom = true;
            desc.Character = false;

            this.actor = PhysicsScene.CreateActor(desc);

            if (this.actor != null)
            {
                this.actor.EnableCollisionListening();
            }
        }

        /// <summary>
        /// Handles a message sent to this component.
        /// </summary>
        /// <param name="message">Message to be handled</param>
        /// <returns>True, if handled, otherwise false</returns>
        public override bool ExecuteMessage(IMessage message)
        {
            // ALL components derived from non-abstract parents need to pass the message to their parent
            // to let the parent class have a chance to use it.
            return base.ExecuteMessage(message);
        }
    }
}
